package com.itheima.controller;
import com.alibaba.dubbo.config.annotation.Reference;
import com.itheima.constant.MessageConstant;
import com.itheima.entity.PageResult;
import com.itheima.entity.QueryPageBean;
import com.itheima.entity.Result;
import com.itheima.pojo.Member;
import com.itheima.service.MemberService;
import com.itheima.service.MemberService01;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

@RestController
@RequestMapping("/member")
public class MemberController {
    @Reference
    private MemberService01 memberService01;
    @RequestMapping("/add")
    public Result add(@RequestBody Member member){
        try{
            memberService01.add(member);
        } catch (Exception e){
            e.getStackTrace();
            return new Result(false, MessageConstant.ADD_MEMBER_FAIL);
        }

        return new Result(true,MessageConstant.ADD_MEMBER_SUCCESS);
    }


    @RequestMapping("/findPage")
    public PageResult findPAge(@RequestBody QueryPageBean queryPageBean){
        PageResult pageResult = memberService01.pageQuery(queryPageBean);
        return  pageResult;

    }
    @RequestMapping("/delete")
    public Result  delete(Integer id){
        try{
            memberService01.deleteById(id);
        }catch (Exception e){
            e.getStackTrace();
            return new Result(false,MessageConstant.DELETE_MEMBER_FAIL);
        }
        return new Result(true,MessageConstant.DELETE_MEMBER_SUCCESS);
    }

    @RequestMapping("/edit")
    public Result  edit(Member member){
        try{
            memberService01.edit(member);
        }catch (Exception e){
            e.getStackTrace();
            return new Result(false,MessageConstant.EDIT_MEMBER_FAIL);
        }
        return new Result(true,MessageConstant.EDIT_MEMBER_SUCCESS);
    }

}
